package org.mzx.shortLink.adminn.service.handler.chain.userGreateGroup;

import lombok.RequiredArgsConstructor;
import org.mzx.shortLink.adminn.common.ThreadLocal.threadlocal;
import org.mzx.shortLink.adminn.dto.Request.ShortLinkGroupSaveReqDTO;
import org.mzx.shortLink.starter.convention.Exception.ServiceException;
import org.redisson.api.RBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * @author mazhenxi
 * @date 2025/4/25
 * @desc 检查分组名是否已经存在
 */
@Component
@RequiredArgsConstructor
public class userGroupCheckName implements userCreateGroupChain{

    @Autowired
    @Qualifier("groupNameCreateCachePenetrationBloomFilter")
    private  RBloomFilter<String> groupNameCreateCachePenetrationBloomFilter;

    @Override
    public void handler(ShortLinkGroupSaveReqDTO requestParam) {
        if(!groupNameCreateCachePenetrationBloomFilter.contains(threadlocal.getLoginUser().getUsername()+requestParam.getName())) {
            throw new ServiceException("该组名已经存在于您的分组之中");
        }
    }

    @Override
    public int getOrder() {
        return 20;
    }
}
